﻿<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 68KB
 *
 * An open source knowledge base script
 *
 * @package		68kb
 * @author		68kb Dev Team
 * @copyright	Copyright (c) 2009, 68 Designs, LLC
 * @license		http://68kb.com/user_guide/license.html
 * @link		http://68kb.com
 * @since		Version 1.0
 */

// ------------------------------------------------------------------------

/**
 * Category Model
 *
 * This class is used to handle the categories data.
 *
 * @package		68kb
 * @subpackage	Models
 * @category	Models
 * @author		68kb Dev Team
 * @link		http://68kb.com/user_guide/overview/categories.html
 * @version 	$Id: category_model.php 89 2009-08-13 01:54:20Z suzkaw68 $
 */
class Category_model extends CI_model
{	
	/**
	 * Constructor
	 *
	 * @uses 	get_settings
	 * @return 	void
	 */
	function __construct()
	{
		parent::__construct();
		$this->load->database();
		log_message('debug', 'Category Model Initialized');
	}
	
	// ------------------------------------------------------------------------
		
	/**
	* Delete Category
	* 
	* @param	int $cat_id The id of the category to delete.
	* @return	true on success.
	*/
	function delete_category($cat_id)
	{
		$cat_id=(int)trim($cat_id);
		$this->db->delete('categories', array('cat_id' => $cat_id)); 
		if ($this->db->affected_rows() > 0) 
		{
			$this->db->cache_delete_all();
			return true;
		} 
		else 
		{
			return false;
		}
	}
	
	// ------------------------------------------------------------------------
	
	/**
 	* Edit Category
 	* 
 	* @param	array $data An array of data.
	* @uses 	format_uri
 	* @return	true on success.
 	*/
	function edit_category($cat_id, $data)
	{
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
 	* Add Category
 	* 
 	* @param	array 	$data An array of data.
	* @uses 	format_uri
 	* @return	mixed 	Id on success.
 	*/
	function add_category($data)
	{
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Get Category By ID.
	 *
	 * Get a single category from its id
	 *
	 * @access	public
	 * @param	int	the unique id
	 * @return	array
	 */
	function get_cat_by_id($id)
	{
		$id=(int)$id;
		$this->db->from('categories')->where('cat_id', $id);
		$query = $this->db->get();
		$data = $query->row();
		$query->free_result();
		return  $data;
	}
	
	
	function getCatAll()
	{
		$cat = array();
		$this->db->from('categories');
		$query = $this->db->get();
		foreach ($query->result() as $row)
		{
			$rs['cat_id']=$row->cat_id;
			$rs['cat_name']=$row->cat_name;
			$rs['cat_url']=$row->cat_uri;
			$cat[]=$rs;
		}
		return $cat;
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Get Category Name By ID.
	 *
	 * Get a single category Name
	 *
	 * @access	public
	 * @param	int	the unique id
	 * @return	string
	 */
	function get_cat_name_by_id($id)
	{
		$this->db->select('cat_name')->from('categories')->where('cat_id', $id);
		$query = $this->db->get();
		$data = $query->row();
		$query->free_result();
		return  $data->cat_name;
	}
	
}
	
/* End of file category_model.php */
/* Location: ./upload/includes/application/models/category_model.php */ 
